package com.yxp.offer;

/**
 * @author      : yang.xp
 * @date        : 2021/8/20 9:53
 * @description : Offer 10- I. 斐波那契数列
 */
public class Problem10_1 {
    public static void main(String[] args) {
        Problem10_1 problem10_1 = new Problem10_1();
        System.out.println(problem10_1.fib(50));
    }

    //
    public int fib(int n) {
        int a = 0, b = 1, sum;
        for (int i = 0; i < n; i++) {
            sum = (a + b) % 1000000007;
            a = b;
            b = sum;
        }
        return a;
    }

    // 下边的方法是错的，这种是算了每个值的斐波那契数列和，
    public int fib1(int n) {
        return add(n);
    }

    public int add(int n) {
        if (n <= 0) {
            return 0;
        }
        if (n == 1) {
            return 1;
        }
        return (add(n - 1) + add(n - 2)) % 1000000007;
    }
}
